import Vue from "vue";
import VueRouter from "vue-router";

Vue.use(VueRouter);

const router = new VueRouter({
    mode: 'hash', // 使用 hash 模式
    routes: [
        {
            path: '/system',
            name: 'Login',
            component: () => import('@/views/Login'),
        },
        {
            path: '/',
            component: () => import('@/layout/Layout'),
            redirect: '/system',
            children: [
                {
                    path: 'dashboard',
                    name: 'Dashboard',
                    component: () => import('@/views/Dashboard'),
                },
                {
                    path: 'test1',
                    name: 'test1',
                    component: () => import('@/views/UserList.vue'),
                },
                {
                    path: 'test2',
                    name: 'test2',
                    component: () => import('@/views/Test2'),
                },
                {
                    path: 'test3',
                    name: 'test3',
                    component: () => import('@/components/HelloWorld.vue'),
                }
            ]
        },
    ]
});

// 路由守卫
router.beforeEach((to, from, next) => {
    if (to.path !== '/system') {
        // TODO: 这里可以添加登录状态检查
        next()
    } else {
        next()
    }
});
export default router;